﻿Public Class FormYZZH
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public ussr As String
    Dim objWorkshopCurrent As New clsWorkshopCurrent
    Dim objPgdMes As New clsPgdMes
    Dim objProdSpec As New clsProdSpec
    Dim objProdInfo As New clsProdInfo
    Dim objGJBinfo As New clsGJBinfo
    Dim objFLBinfo As New clsFLBinfo
    Dim objJpMst As New clsJpMst
    Private Sub FormYZZH_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        initForm()
        setDgvData()
    End Sub

    Public Sub setDgvData()
        Dim dtProdInfo As DataTable = objProdInfo.getProdInfoListByStatus("1")
        dgv.AutoGenerateColumns = False
        dgv.DataSource = dtProdInfo
    End Sub

    Public Sub initForm()
        Dim dt As DataTable = objWorkshopCurrent.GetListByWorkShopIdAndCurrentSection("0", "YZZ")
        cmb_support_model.DisplayMember = "support_model"
        cmb_support_model.ValueMember = "b_pgd_sys_id"
        cmb_support_model.DataSource = dt
        If dt.Rows.Count > 0 Then
            If String.IsNullOrEmpty(cmb_support_model.Text) = False Then
                cmb_support_model.SelectedIndex = 0
                Dim dtPgdMes As DataTable = objPgdMes.getList(cmb_support_model.SelectedValue.ToString())
                txt_mes_project_code.Text = dtPgdMes.Rows(0)("mes_project_code").ToString()
                txt_mes_project_name.Text = dtPgdMes.Rows(0)("mes_project_name").ToString()
                lblProdSpecName.Text = objProdSpec.getSpecNameByID(cmb_support_model.Text)
                Dim dtPS As DataTable = objProdSpec.selectAllbySpecId(cmb_support_model.Text)
                If dtPS.Rows.Count > 0 Then
                    txtFlbType.Text = dtPS.Rows(0)("flb_type").ToString()
                    lblGJBXH.Text = dtPS.Rows(0)("gjb_type").ToString()
                    lblJPZL.Text = dtPS.Rows(0)("rubber_layer_thickness_total").ToString()
                    lblGJBZL.Text = dtPS.Rows(0)("gjb_st_wt").ToString()
                    lblJPPS.Text = dtPS.Rows(0)("jp_layer_num").ToString()
                    lblGJBPS.Text = dtPS.Rows(0)("gjb_layer_num").ToString()
                    lblFLBXH.Text = dtPS.Rows(0)("flb_type").ToString()
                    Dim dtMJ As DataTable = objJpMst.getMstJpByMaterialCode(dtPgdMes.Rows(0)("jp_type").ToString())
                    lblJLXH.Text = dtMJ.Rows(0)("model").ToString()
                End If
            Else
                txt_mes_project_code.Text = String.Empty
                txt_mes_project_name.Text = String.Empty
                lblProdSpecName.Text = String.Empty
                txtFlbType.Text = String.Empty
                lblJLXH.Text = String.Empty
                lblGJBXH.Text = "0"
                lblJPZL.Text = "0"
                lblGJBZL.Text = "0"
                lblJPPS.Text = "0"
                lblGJBPS.Text = "0"
                lblFLBXH.Text = "0"
            End If
        End If
    End Sub
    Private Function check() As Boolean
        Dim rtn As Boolean = True
        If lblFLBXH.Text <> txt_flb_type.Text Then
            MsgBox("法兰板型号不符！")
            Return False
        End If
        If lblGJBXH.Text <> lblGJBXH_SJ.Text Then
            MsgBox("骨架板型号不符！")
            Return False
        End If
        If lblGJBPS.Text <> lblGJBPS_SJ.Text Then
            MsgBox("骨架板片数不符！")
            Return False
        End If
        If CDbl(lblGJBZL_SJ.Text) <= 0 Then
            MsgBox("骨架板重量需 ＞ 0！")
            Return False
        End If
        If lblJPPS.Text <> txtJP_Piece_num.Text Then
            MsgBox("胶片片数不符！")
            Return False
        End If
        If txtJP_ZL.Value <= 0 Then
            MsgBox("胶片重量需 ＞ 0！")
            Return False
        End If
        Return rtn
    End Function
    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        initForm()
        If check() Then
            Dim rtn As Integer = objProdInfo.updateProdInfo(lblprodid.Text.Trim(), lblgjb_sys_id.Text.Trim(), txtGJBDLNo.Text.Trim(), txtJP_ZL.Text.Trim(), lblJLXH.Text.Trim())
            If rtn <> -2 Then
                Clear()
                initForm()
                setDgvData()
                MsgBox("保存成功")
            Else
                MsgBox("保存失败")
            End If
        End If
    End Sub
    Private Sub Clear()
        lblprodid.Text = String.Empty
        txt_tray_no.Text = String.Empty
        txt_flb_type.Text = String.Empty
        txtGJBDLNo.Text = String.Empty
        lblGJBXH_SJ.Text = String.Empty
        lblGJBPS_SJ.Text = "0"
        lblLabelNo.Text = String.Empty
        lblGJBZL_SJ.Text = "0.0"
        lblgjb_sys_id.Text = String.Empty
        txtJP_Piece_num.Value = 0
        txtJP_ZL.Value = 0
    End Sub
    Private Sub txtGJBDLNo_KeyDown(sender As Object, e As KeyEventArgs) Handles txtGJBDLNo.KeyDown
        If String.IsNullOrEmpty(txtGJBDLNo.Text.Trim()) = False Then
            If e.KeyCode = Keys.Enter Then
                'txtGJBDLNo.Text.Remove(txtGJBDLNo.Text.Length - 1)
                txtGJBDLNo.Text = txtGJBDLNo.Text.ToUpper()
                Dim dt As DataTable = objGJBinfo.getListByDlNo(txtGJBDLNo.Text.Trim())
                If dt.Rows.Count > 0 Then
                    lblGJBPS_SJ.Text = dt.Rows(0)("layer_num")
                    lblGJBZL_SJ.Text = dt.Rows(0)("wt")
                    lblGJBXH_SJ.Text = dt.Rows(0)("gjb_type")
                    lblgjb_sys_id.Text = dt.Rows(0)("sys_id")
                    If dt.Rows(0)("label_no").Equals(DBNull.Value) = False Then
                        lblLabelNo.Text = dt.Rows(0)("label_no")
                        lblLabelNo.Text = String.Format("{0}号标签", lblLabelNo.Text)
                    End If
                Else
                    lblGJBPS_SJ.Text = "0"
                    lblGJBZL_SJ.Text = "0.0"
                    lblGJBXH_SJ.Text = String.Empty
                    lblgjb_sys_id.Text = String.Empty
                    lblLabelNo.Text = String.Empty
                End If
            End If
        End If

    End Sub

    Private Sub txt_tray_no_KeyDown(sender As Object, e As KeyEventArgs) Handles txt_tray_no.KeyDown
        If String.IsNullOrEmpty(txt_tray_no.Text.Trim()) = False Then
            If e.KeyCode = Keys.Enter Then
                txt_tray_no.Text = txt_tray_no.Text.ToUpper()
                Dim dtPI As DataTable = objProdInfo.getProdInfoListByTrayNoAndStatus(txt_tray_no.Text.Trim(), "0")
                If dtPI.Rows.Count > 0 Then
                    lblprodid.Text = dtPI.Rows(0)("prod_id").ToString()
                    Dim dt As DataTable = objFLBinfo.getFlbInfoBySysId(dtPI.Rows(0)("flb_sys_id").ToString())
                    If dt.Rows.Count > 0 Then
                        txt_flb_type.Text = dt.Rows(0)("flb_type").ToString()
                    Else
                        txt_flb_type.Text = String.Empty
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub txtNumber_MouseDown(sender As Object, e As MouseEventArgs) Handles txtJP_Piece_num.MouseDown, txtJP_ZL.MouseDown, txt_jp_wt.MouseDown
        sender.Focus
        UcDigitalKeyboard1 = New ucDigitalKeyboard

        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()

    End Sub

    Private Sub btnSet_Click(sender As Object, e As EventArgs) Handles btnSet.Click
        Dim formPlanMes As New FormPlanMes()
        formPlanMes.origin = "FormYZZH"
        formPlanMes.usr = ussr
        formPlanMes.ShowDialog(Me)
    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        Dim rtn As Integer = objWorkshopCurrent.updateDataClear("0", "YZZ")
        If rtn = -2 Then
            MsgBox(btnClear.Text + "失败")
        Else
            MsgBox(btnClear.Text + "成功")
            initForm()
        End If
    End Sub

    Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged
        If dgv.SelectedRows.Count > 0 Then
            txt_jp_wt.Value = dgv.SelectedRows(0).Cells("jp_all_wt").Value.ToString()
        End If
    End Sub

    Private Sub btnSaveJpAllWt_Click(sender As Object, e As EventArgs) Handles btnSaveJpAllWt.Click
        If dgv.SelectedRows.Count > 0 Then
            Dim rtn As Integer = objProdInfo.updateProdInfoJpAllWt(dgv.SelectedRows(0).Cells("prod_id").Value.ToString(), txt_jp_wt.Text.Trim())
            If rtn <> -2 Then
                setDgvData()
                MsgBox("保存成功")
            Else
                MsgBox("保存失败")
            End If
        End If
    End Sub
End Class